﻿using CleanArchitecture.Infrastructure.Entities;
using CleanArchitecture.Infrastructure.Interfaces.Security;
using Microsoft.AspNetCore.Mvc;
using System.Linq;

namespace CleanArchitecture.Web.Components
{
    /// <summary>
    /// 系统模块表单数据行操作按钮组件
    /// 配合layui-table组件使用
    /// </summary>
    public class RecordButtonViewComponent : ViewComponent
    {
        private readonly IPermissionService _permissionService;

        public RecordButtonViewComponent(IPermissionService permissionService)
        {
            _permissionService = permissionService;
        }

        public IViewComponentResult Invoke()
        {
            var moduleAssignedBtns = _permissionService.GetSystemModuleAssignedButtons(Request.Path.Value);
            if (moduleAssignedBtns == null || moduleAssignedBtns.Count == 0 || !moduleAssignedBtns.Any(b => b.ButtonType == EntityEnumConfig.SystemModuleButtonType.RecordBtn))
                return Content("");
            return View(moduleAssignedBtns.Where(m => m.ButtonType == EntityEnumConfig.SystemModuleButtonType.RecordBtn).ToList());
        }
    }
}
